package test;

/**
 * @description:
 * @className: CompileUp
 * @package: test
 * @author: qiufeng@hsyuntai.com
 * @date: 2019/5/15 10:22
 * @copyright: 版权归 HSYUNTAI 所有
 */
public class CompileUp {

    public static void main(String[] args) {

        // 公共子表达式消除
        // 未优化前
        int a = 0, b = 0, c = 0, d = 0;
        int d1= (c * b) * 12 + a + (a + b + c);
        // 公共子表达式消除后
        int E = c * b;
        int d2 = E * 12 + a + (E + a);
        // 代数化简后
        int d3 = 13 * E + 2 * a;

        // 数据边界检查消除
        int [] arrs = new int[10000];
        for(int i = 0;i < 10000;i++){
            arrs[i] = i;
        }

    }

    // 方法内联
    // 优化前
    public static void foo(Object obj){
        if(obj != null){
            System.out.println("do something");
        }
    }
    public static void testInline1(String[] args){
        Object obj = null;
        foo(obj);
    }
    // 优化后
    public static void testInline2(String[] args){
        Object obj = null;
        if(obj != null){
            System.out.println("do something");
        }
    }

}
